#include "ClientSeekView.h"

ClientSeekView::ClientSeekView(Screen *s, Model *m, LPDIRECT3DDEVICE9 dd3d): View(s, m, dd3d)
{
  _model = (ClientSeekModel*)m;
  D3DXCreateFont(_dd3dDevice, 60, 0, FW_NORMAL, 1, false, DEFAULT_CHARSET,
                 OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH || FF_DONTCARE,
                 "Arial", &_font);
  InitRects();
}

void ClientSeekView::InitRects(void)
{
  SetRect(&_titleRect, 100, 100, 1000, 200);
  SetRect(&_newsRect, 100, 500, 1000, 600);
}

ClientSeekView::~ClientSeekView(void)
{
  _font->Release();
}

void ClientSeekView::Draw(void)
{
  HRESULT res;
  if(background != NULL)
  {
    GlobalDebug::GetInstance()->AssertAndLogResult(_sprite->Draw(this->background, NULL, NULL, NULL, D3DCOLOR_XRGB(255,255,255)), "ClientSeekView::Draw background");
    _sprite->End();
    _sprite->Begin(D3DXSPRITE_ALPHABLEND);
  }

  res = _font->DrawTextA(NULL, _clientSeekTitle, _clientSeekTitleLen, 
                         &_titleRect,  DT_CENTER | DT_VCENTER, _clientSeekTextColor);

  if(_model->IsConnected())
  {
    res = _font->DrawTextA(NULL, _clientSeekNews1, _clientSeekNews1Len, &_newsRect,
                           DT_CENTER | DT_VCENTER, _clientSeekTextColor);
  }
  else
  {
    res = _font->DrawTextA(NULL, _clientSeekNews2, _clientSeekNews2Len, &_newsRect,
                           DT_CENTER | DT_VCENTER, _clientSeekTextColor);
  }
}

void ClientSeekView::HandleMessage(Message* msg)
{
  delete msg;
}

void ClientSeekView::PreRender(void)
{
  GlobalDebug::GetInstance()->AssertAndLogResult(_sprite->Begin(D3DXSPRITE_ALPHABLEND), "View::PreRender Sprite::Begin");
}

void ClientSeekView::PostRender(void)
{
  GlobalDebug::GetInstance()->AssertAndLogResult(_sprite->End(), "View::PostRender Sprite::End");
}
